package com.photography.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.photography.pojo.Serial;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SerialMapper extends BaseMapper<Serial> {

    @Select("SELECT s.* FROM tb_order o,`serial` s,serial_order s_o WHERE s.id=s_o.serialid AND o.id=s_o.orderid AND o.id =#{orderId}")
    List<Serial> findSerialByOrderId(String orderId);

    @Insert("INSERT INTO serial_product (`serialid`, `productid`) \n" +
            "VALUES(#{serialId}, #{productId})")
    void addSerialAndProduct(@Param("serialId") String serialId, @Param("productId") String productId);

    @Delete("DELETE FROM serial_product WHERE serialid=#{serialId}")
    void deleteSerialAndProduct(@Param("serialId") String serialId);

    @Select("SELECT productid FROM serial_product WHERE serialid=#{serialId}")
    List<String> findProductIdBySerialId(@Param("serialId") String serialId);
}
